<em>import React from 'react'</em>
<em>import <b>ReactDOM</b> from 'react-dom'</em>

<em>export default class <u>AddLast</u> extends React.Component</em>{
	<em># 挂载时执行</em>
	<q>componentDidMount</q>( ){
		<em>if</em>(<b>!this.props.isUpdate</b>){ <s>this.renderSubtree</s>( ) }
	}
	<em># 获取指定 dom</em>
	<s>getNode</s> = ( ) => {
		<em>const</em> { <u>el</u> } = <u>this.props</u>
		<em>const</em> <u>node</u> = <em>document.querySelector</em>( <u>el</u> )
		<em>return </em> <u>node</u> ? <u>node</u> : <b>document.body</b>
	}
	<em># 更新时执行</em>
	<q>componentDidUpdate</q>( ){
		<em>if</em>(<b>this.props.isUpdate</b>){ <s>this.renderSubtree</s>( ) }
	}
	<em># 将要销毁时执行</em>
	<q>componentWillUnmount</q>( ){
		<u>this.el</u> && <s>this.getNode( )</s>.<b>removeChild</b>(<u>this.el</u>) 	<em>// 移出节点</em>
	}
	<em># 添加节点</em>
	<i>retContainer</i> = ( ) =>{
		if(!<u>this.el</u>){
			<em>const node</em> = <b>document.createElement</b>(<u>this.props.tag||'div'</u>)
			<em>node.setAttribute('name',this.props.name)</em> 		<em>// 设置节点属性</em>
			<u>this.el</u> = <em>node</em>
			<s>this.getNode( )</s>.<b>appendChild</b>(<u>this.el</u>)
		}
		<em>return</em> <u>this.el</u>
	}
	<em># 获取 children 内容</em>
	<i>retContent</i> = ( ) =>  &lt;&gt;{ <u>this.props.children</u> }&lt;/&gt;
	<em># 渲染到节点</em>
	<s>renderSubtree</s> = ( ) => {
		<b>ReactDOM.unstable_renderSubtreeIntoContainer</b>(
			<i>this</i>,
			<i>this.retContent( )</i>,
			<i>this.retContainer( )</i>,
		)
	}
	
	<b>render( ){ return null }</b>
}
<em># 使用</em>
<em>&lt;<u>AddLast</u> <s>name</s>='style' <s>tag</s>='style' <s>el</s>='head'&gt;</em>
	<em>&lt;div&gt;&lt;div&gt;</em>
<em>&lt;/<u>AddLast</u>&gt;</em>